﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Maticsoft.DAL
{
	/// <summary>
	/// 数据访问类:ZB_ZDXX
	/// </summary>
	public partial class ZB_ZDXX
	{
		public ZB_ZDXX()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("ZDID", "ZB_ZDXX"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ZDID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from ZB_ZDXX");
			strSql.Append(" where ZDID=@ZDID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ZDID", SqlDbType.Int,4)			};
			parameters[0].Value = ZDID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Maticsoft.Model.ZB_ZDXX model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into ZB_ZDXX(");
			strSql.Append("ZDID,ZDBH,CardNum,FWBH,ZDMS,WZXX,ZDLX,QYID,SCJG,SCSJ_m,SCSJ_s,SBZT,ZBX,ZBY,ZBCS,FBCS,SSLL,YWSD,SCJG_history,FZT,ModelID,SB_Authorization,XSZT,KZZT,SX)");
			strSql.Append(" values (");
			strSql.Append("@ZDID,@ZDBH,@CardNum,@FWBH,@ZDMS,@WZXX,@ZDLX,@QYID,@SCJG,@SCSJ_m,@SCSJ_s,@SBZT,@ZBX,@ZBY,@ZBCS,@FBCS,@SSLL,@YWSD,@SCJG_history,@FZT,@ModelID,@SB_Authorization,@XSZT,@KZZT,@SX)");
			SqlParameter[] parameters = {
					new SqlParameter("@ZDID", SqlDbType.Int,4),
					new SqlParameter("@ZDBH", SqlDbType.VarChar,11),
					new SqlParameter("@CardNum", SqlDbType.VarChar,20),
					new SqlParameter("@FWBH", SqlDbType.VarChar,11),
					new SqlParameter("@ZDMS", SqlDbType.VarChar,50),
					new SqlParameter("@WZXX", SqlDbType.VarChar,100),
					new SqlParameter("@ZDLX", SqlDbType.Int,4),
					new SqlParameter("@QYID", SqlDbType.Char,5),
					new SqlParameter("@SCJG", SqlDbType.VarChar,10),
					new SqlParameter("@SCSJ_m", SqlDbType.VarChar,10),
					new SqlParameter("@SCSJ_s", SqlDbType.VarChar,10),
					new SqlParameter("@SBZT", SqlDbType.Char,10),
					new SqlParameter("@ZBX", SqlDbType.Float,8),
					new SqlParameter("@ZBY", SqlDbType.Float,8),
					new SqlParameter("@ZBCS", SqlDbType.VarChar,50),
					new SqlParameter("@FBCS", SqlDbType.VarChar,50),
					new SqlParameter("@SSLL", SqlDbType.VarChar,50),
					new SqlParameter("@YWSD", SqlDbType.Char,1),
					new SqlParameter("@SCJG_history", SqlDbType.Char,1),
					new SqlParameter("@FZT", SqlDbType.Char,1),
					new SqlParameter("@ModelID", SqlDbType.VarChar,8),
					new SqlParameter("@SB_Authorization", SqlDbType.Char,1),
					new SqlParameter("@XSZT", SqlDbType.Char,1),
					new SqlParameter("@KZZT", SqlDbType.Char,1),
					new SqlParameter("@SX", SqlDbType.Char,1)};
			parameters[0].Value = model.ZDID;
			parameters[1].Value = model.ZDBH;
			parameters[2].Value = model.CardNum;
			parameters[3].Value = model.FWBH;
			parameters[4].Value = model.ZDMS;
			parameters[5].Value = model.WZXX;
			parameters[6].Value = model.ZDLX;
			parameters[7].Value = model.QYID;
			parameters[8].Value = model.SCJG;
			parameters[9].Value = model.SCSJ_m;
			parameters[10].Value = model.SCSJ_s;
			parameters[11].Value = model.SBZT;
			parameters[12].Value = model.ZBX;
			parameters[13].Value = model.ZBY;
			parameters[14].Value = model.ZBCS;
			parameters[15].Value = model.FBCS;
			parameters[16].Value = model.SSLL;
			parameters[17].Value = model.YWSD;
			parameters[18].Value = model.SCJG_history;
			parameters[19].Value = model.FZT;
			parameters[20].Value = model.ModelID;
			parameters[21].Value = model.SB_Authorization;
			parameters[22].Value = model.XSZT;
			parameters[23].Value = model.KZZT;
			parameters[24].Value = model.SX;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Maticsoft.Model.ZB_ZDXX model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update ZB_ZDXX set ");
			strSql.Append("ZDBH=@ZDBH,");
			strSql.Append("CardNum=@CardNum,");
			strSql.Append("FWBH=@FWBH,");
			strSql.Append("ZDMS=@ZDMS,");
			strSql.Append("WZXX=@WZXX,");
			strSql.Append("ZDLX=@ZDLX,");
			strSql.Append("QYID=@QYID,");
			strSql.Append("SCJG=@SCJG,");
			strSql.Append("SCSJ_m=@SCSJ_m,");
			strSql.Append("SCSJ_s=@SCSJ_s,");
			strSql.Append("SBZT=@SBZT,");
			strSql.Append("ZBX=@ZBX,");
			strSql.Append("ZBY=@ZBY,");
			strSql.Append("ZBCS=@ZBCS,");
			strSql.Append("FBCS=@FBCS,");
			strSql.Append("SSLL=@SSLL,");
			strSql.Append("YWSD=@YWSD,");
			strSql.Append("SCJG_history=@SCJG_history,");
			strSql.Append("FZT=@FZT,");
			strSql.Append("ModelID=@ModelID,");
			strSql.Append("SB_Authorization=@SB_Authorization,");
			strSql.Append("XSZT=@XSZT,");
			strSql.Append("KZZT=@KZZT,");
			strSql.Append("SX=@SX");
			strSql.Append(" where ZDID=@ZDID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ZDBH", SqlDbType.VarChar,11),
					new SqlParameter("@CardNum", SqlDbType.VarChar,20),
					new SqlParameter("@FWBH", SqlDbType.VarChar,11),
					new SqlParameter("@ZDMS", SqlDbType.VarChar,50),
					new SqlParameter("@WZXX", SqlDbType.VarChar,100),
					new SqlParameter("@ZDLX", SqlDbType.Int,4),
					new SqlParameter("@QYID", SqlDbType.Char,5),
					new SqlParameter("@SCJG", SqlDbType.VarChar,10),
					new SqlParameter("@SCSJ_m", SqlDbType.VarChar,10),
					new SqlParameter("@SCSJ_s", SqlDbType.VarChar,10),
					new SqlParameter("@SBZT", SqlDbType.Char,10),
					new SqlParameter("@ZBX", SqlDbType.Float,8),
					new SqlParameter("@ZBY", SqlDbType.Float,8),
					new SqlParameter("@ZBCS", SqlDbType.VarChar,50),
					new SqlParameter("@FBCS", SqlDbType.VarChar,50),
					new SqlParameter("@SSLL", SqlDbType.VarChar,50),
					new SqlParameter("@YWSD", SqlDbType.Char,1),
					new SqlParameter("@SCJG_history", SqlDbType.Char,1),
					new SqlParameter("@FZT", SqlDbType.Char,1),
					new SqlParameter("@ModelID", SqlDbType.VarChar,8),
					new SqlParameter("@SB_Authorization", SqlDbType.Char,1),
					new SqlParameter("@XSZT", SqlDbType.Char,1),
					new SqlParameter("@KZZT", SqlDbType.Char,1),
					new SqlParameter("@SX", SqlDbType.Char,1),
					new SqlParameter("@ZDID", SqlDbType.Int,4)};
			parameters[0].Value = model.ZDBH;
			parameters[1].Value = model.CardNum;
			parameters[2].Value = model.FWBH;
			parameters[3].Value = model.ZDMS;
			parameters[4].Value = model.WZXX;
			parameters[5].Value = model.ZDLX;
			parameters[6].Value = model.QYID;
			parameters[7].Value = model.SCJG;
			parameters[8].Value = model.SCSJ_m;
			parameters[9].Value = model.SCSJ_s;
			parameters[10].Value = model.SBZT;
			parameters[11].Value = model.ZBX;
			parameters[12].Value = model.ZBY;
			parameters[13].Value = model.ZBCS;
			parameters[14].Value = model.FBCS;
			parameters[15].Value = model.SSLL;
			parameters[16].Value = model.YWSD;
			parameters[17].Value = model.SCJG_history;
			parameters[18].Value = model.FZT;
			parameters[19].Value = model.ModelID;
			parameters[20].Value = model.SB_Authorization;
			parameters[21].Value = model.XSZT;
			parameters[22].Value = model.KZZT;
			parameters[23].Value = model.SX;
			parameters[24].Value = model.ZDID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ZDID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from ZB_ZDXX ");
			strSql.Append(" where ZDID=@ZDID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ZDID", SqlDbType.Int,4)			};
			parameters[0].Value = ZDID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string ZDIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from ZB_ZDXX ");
			strSql.Append(" where ZDID in ("+ZDIDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Maticsoft.Model.ZB_ZDXX GetModel(int ZDID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ZDID,ZDBH,CardNum,FWBH,ZDMS,WZXX,ZDLX,QYID,SCJG,SCSJ_m,SCSJ_s,SBZT,ZBX,ZBY,ZBCS,FBCS,SSLL,YWSD,SCJG_history,FZT,ModelID,SB_Authorization,XSZT,KZZT,SX from ZB_ZDXX ");
			strSql.Append(" where ZDID=@ZDID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ZDID", SqlDbType.Int,4)			};
			parameters[0].Value = ZDID;

			Maticsoft.Model.ZB_ZDXX model=new Maticsoft.Model.ZB_ZDXX();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Maticsoft.Model.ZB_ZDXX DataRowToModel(DataRow row)
		{
			Maticsoft.Model.ZB_ZDXX model=new Maticsoft.Model.ZB_ZDXX();
			if (row != null)
			{
				if(row["ZDID"]!=null && row["ZDID"].ToString()!="")
				{
					model.ZDID=int.Parse(row["ZDID"].ToString());
				}
				if(row["ZDBH"]!=null)
				{
					model.ZDBH=row["ZDBH"].ToString();
				}
				if(row["CardNum"]!=null)
				{
					model.CardNum=row["CardNum"].ToString();
				}
				if(row["FWBH"]!=null)
				{
					model.FWBH=row["FWBH"].ToString();
				}
				if(row["ZDMS"]!=null)
				{
					model.ZDMS=row["ZDMS"].ToString();
				}
				if(row["WZXX"]!=null)
				{
					model.WZXX=row["WZXX"].ToString();
				}
				if(row["ZDLX"]!=null && row["ZDLX"].ToString()!="")
				{
					model.ZDLX=int.Parse(row["ZDLX"].ToString());
				}
				if(row["QYID"]!=null)
				{
					model.QYID=row["QYID"].ToString();
				}
				if(row["SCJG"]!=null)
				{
					model.SCJG=row["SCJG"].ToString();
				}
				if(row["SCSJ_m"]!=null)
				{
					model.SCSJ_m=row["SCSJ_m"].ToString();
				}
				if(row["SCSJ_s"]!=null)
				{
					model.SCSJ_s=row["SCSJ_s"].ToString();
				}
				if(row["SBZT"]!=null)
				{
					model.SBZT=row["SBZT"].ToString();
				}
				if(row["ZBX"]!=null && row["ZBX"].ToString()!="")
				{
					model.ZBX=decimal.Parse(row["ZBX"].ToString());
				}
				if(row["ZBY"]!=null && row["ZBY"].ToString()!="")
				{
					model.ZBY=decimal.Parse(row["ZBY"].ToString());
				}
				if(row["ZBCS"]!=null)
				{
					model.ZBCS=row["ZBCS"].ToString();
				}
				if(row["FBCS"]!=null)
				{
					model.FBCS=row["FBCS"].ToString();
				}
				if(row["SSLL"]!=null)
				{
					model.SSLL=row["SSLL"].ToString();
				}
				if(row["YWSD"]!=null)
				{
					model.YWSD=row["YWSD"].ToString();
				}
				if(row["SCJG_history"]!=null)
				{
					model.SCJG_history=row["SCJG_history"].ToString();
				}
				if(row["FZT"]!=null)
				{
					model.FZT=row["FZT"].ToString();
				}
				if(row["ModelID"]!=null)
				{
					model.ModelID=row["ModelID"].ToString();
				}
				if(row["SB_Authorization"]!=null)
				{
					model.SB_Authorization=row["SB_Authorization"].ToString();
				}
				if(row["XSZT"]!=null)
				{
					model.XSZT=row["XSZT"].ToString();
				}
				if(row["KZZT"]!=null)
				{
					model.KZZT=row["KZZT"].ToString();
				}
				if(row["SX"]!=null)
				{
					model.SX=row["SX"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ZDID,ZDBH,CardNum,FWBH,ZDMS,WZXX,ZDLX,QYID,SCJG,SCSJ_m,SCSJ_s,SBZT,ZBX,ZBY,ZBCS,FBCS,SSLL,YWSD,SCJG_history,FZT,ModelID,SB_Authorization,XSZT,KZZT,SX ");
			strSql.Append(" FROM ZB_ZDXX ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ZDID,ZDBH,CardNum,FWBH,ZDMS,WZXX,ZDLX,QYID,SCJG,SCSJ_m,SCSJ_s,SBZT,ZBX,ZBY,ZBCS,FBCS,SSLL,YWSD,SCJG_history,FZT,ModelID,SB_Authorization,XSZT,KZZT,SX ");
			strSql.Append(" FROM ZB_ZDXX ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM ZB_ZDXX ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ZDID desc");
			}
			strSql.Append(")AS Row, T.*  from ZB_ZDXX T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "ZB_ZDXX";
			parameters[1].Value = "ZDID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

